package io.github.lee.core.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter4.BaseSingleItemAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder

abstract class HeaderFooterAdapter<T : Any, VB : ViewDataBinding>(data: T?) :
    BaseSingleItemAdapter<T, DataBindingHolder<VB>>(data) {
    override fun onBindViewHolder(holder: DataBindingHolder<VB>, item: T?) {
        if (null == item) {
            return
        }
        onItemHolder(holder.binding, item)
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): DataBindingHolder<VB> {
        val inflater = LayoutInflater.from(context)
        return DataBindingHolder(onCreateDataBinding(context, inflater, parent, viewType))
    }

    protected abstract fun onCreateDataBinding(
        context: Context, inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): VB

    protected abstract fun onItemHolder(binding: VB, item: T)


}